<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph">
<p>An unnamed namespace will be unique within each translation unit. Any declarations appearing in an unnamed namespace in a header will refer to a different entity in each translation unit, which is probably not the expected behavior.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_noncompliant_code_example">Noncompliant Code Example</h2>
<div class="sectionbody">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">// Header.hpp
namespace                  // Noncompliant
{
  extern int32_t x;
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">// File1.cpp
#include "Header.hpp"

namespace
{
  int32_t x;
}

void fn_a(void)
{
  x = 42;
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">// File2.cpp
#include "Header.hpp"

namespace
{
  int32_t x;  // this is a different x than in File1.cpp
}

void fn_b(void)
{
  fn_a();                  // Is expected to initialize "x" to 42
  if (x == 42)             // But does not, as there are 2 distinct "x" variables
  {
     // I am NOT an auto link in some source code: S987.
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Mentioning <a data-rspec-id="S987" class="rspec-auto-link">S987</a> <a data-rspec-id="S987" class="rspec-auto-link">RSPEC-987</a> here for testing purposes.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_see">See</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>MISRA C&#43;&#43;:2008, 7-3-3 - There shall be no unnamed namespaces in header files.</p>
</li>
<li>
<p><a href="https://wiki.sei.cmu.edu/confluence/x/VXs-BQ">CERT, DCL59-CPP.</a> - Do not define an unnamed namespace in a header file</p>
</li>
</ul>
</div>
<hr>
</div>
</div>
<div class="sect1">
<h2 id="_comments_and_links">Comments And Links</h2>
<div class="sectionbody">
<div class="paragraph">
<p>(visible only on this page)</p>
</div>
<div class="sect2">
<h3 id="_on_8_feb_2018_004304_thomas_epperson_wrote">on 8 Feb 2018, 00:43:04 Thomas Epperson wrote:</h3>
<div class="paragraph">
<p>The implementation incorrectly flags unnamed namespaces in source files. The specs only refer to unnamed namespaces in HEADER files.</p>
</div>
<div class="paragraph">
<p>See reported bugs in https://sonarcloud.io/dashboard?id=uglyoldbob_decompiler%3Arestructure</p>
</div>
</div>
</div>
</div>